 <?php
include "../config/idcombos.php";

function ret_array($sql) {
    include "../config/connection.php";

    $query = $sql;
    $statement = oci_parse($conn, $query);
    $nrows;
    $res;
    @oci_execute($statement);
    $nrows = oci_fetch_all($statement, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC);
    oci_close($conn);

    return $res;
}
/**
 * Función que ejecuta consultas con auto limpieza.
 * $arrparams debe contener los identificadores para oci_bind_by name
 * asociados a sus respectivos valores
 * @param string $strsent
 * @param array $arrparams
 * @param string $db
 * @return array
 */
function real_ret_arrayi($strsent, $arrparams, $db="FichaBDLocal") {
    $comb = getId($db);
    $user = $comb["user"];
    $host = $comb["host"];
    $pass = $comb["pass"];
    $nrows;
    $res;
    // en este orden debido a que el include depende de las variables de arriba
    // YAY, FIFTIES
    // TODO: dejar bien
    include "../config/connection.php";
    $statement = oci_parse($conn, $strsent);
    foreach (array_keys($arrparams) as $k) {
        oci_bind_by_name($statement, $k, $arrparams[$k]);
    }
    @oci_execute($statement);

    $nrows = oci_fetch_all($statement, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC);
    oci_close($conn);

    return $res;
}

function real_parsei($strsent, $arrparams, $id_retorno="", $db="FichasBDLocal" ) {
    $comb = getId($db);
    $user = $comb["user"];
    $host = $comb["host"];
    $pass = $comb["pass"];
    $encod = "AL32UTF8";
    $nrows;
    $res;
    // en este orden debido a que el include depende de las variables de arriba
    // YAY, FIFTIES
    // TODO: dejar bien
    include "../config/connection.php";
    $statement = oci_parse($conn, $strsent);

    foreach (array_keys($arrparams) as $k) {
        
        oci_bind_by_name($statement, $k, $arrparams[$k]);
    }
    if ($id_retorno) {
        oci_bind_by_name($statement, $id_retorno, $res);
    }

    oci_execute($statement);

    oci_commit($conn);
    oci_free_statement($statement);
    return $res;
}

function parse($sql) {
    include "../config/connection.php";

    $query = $sql;
    $statement = oci_parse($conn, $query);
    oci_execute($statement, OCI_DEFAULT);
    oci_commit($conn);
    oci_free_statement($statement);

//        $stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (123)');
//        $res = oci_execute ($statement);
    oci_close($conn);
    return $res;
}

?>